//
//  Cloud_tableViewCellOne.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Cloud_tableViewCellOne.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Cloud_tableViewCellOne ()<UITextFieldDelegate>
@property (nonatomic, strong) BaseView *View;
@property (nonatomic, strong) UIView *viewLineO;
@property (nonatomic, strong) UIView *viewLineT;
@end
@implementation Cloud_tableViewCellOne

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self notification];
    }
    return self;
}
- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    // lable
    _lableName = [[BaseLabel alloc] init];
    _lableName.text = @"姓名";
    [_View addSubview:_lableName];
    _lablePhone = [[BaseLabel alloc] init];
    _lablePhone.text = @"联系电话";
    [_View addSubview:_lablePhone];
    _lableWei = [[BaseLabel alloc] init];
    _lableWei.text = @"微信号";
    [_View addSubview:_lableWei];
    // textfield
    _textFieldName = [[BaseTextField alloc] init];
    _textFieldName.placeholder = @"送检人姓名";
    _textFieldName.delegate = self;
    [_View addSubview:_textFieldName];
    _textFieldPhone = [[BaseTextField alloc] init];
    _textFieldPhone.delegate = self;
    _textFieldPhone.placeholder = @"联系电话";
    [_View addSubview:_textFieldPhone];
    _textFieldWei = [[BaseTextField alloc] init];
    _textFieldWei.delegate = self;
    _textFieldWei.placeholder = @"微信号";
    [_View addSubview:_textFieldWei];
    
    // 横线
    _viewLineO = [[UIView alloc] init];
    _viewLineO.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineO];
    _viewLineT = [[UIView alloc] init];
    _viewLineT.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineT];
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
    }];
    // lable 的约束
    [_lableName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.33333);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lablePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableName.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.33333);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableWei mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lablePhone.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.33333);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    // textfield 的约束
    [_textFieldName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableName.mas_right).mas_offset(10);
        make.top.mas_equalTo(_View.mas_top);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lablePhone.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldName.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldWei mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableWei.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldPhone.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    
    // 横条
    [_viewLineO mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldName.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldPhone.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
}
#pragma mark - textField代理
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

@end
